home *** CD-ROM | disk | FTP | other *** search
- /*
- * file termio.c:
- *
- * The functions in this file
- * negotiate with the operating system
- * for characters, and write characters in
- * a barely buffered fashion on the display.
- * All operating systems.
- * dal: added highlight and normal text attribute
- * functions, but ansi and termcap need to have
- * the hooks filled in.
- */
- #include <stdio.h>
- #include "ed.h"
-
- #if AtST
- /* overlay "me2" dal: can't do this in Alcyon C */
-
- /*
- * dal: These functions switch the mouse in and out of cursor streaming mode
- */
- mouse_live()
- {
- Ikbdws(4, m_init);
- }
-
- mouse_dead()
- {
- Ikbdws(2, "\007\001\010");
- }
-
- /*
- * dal: These functions adjust to motion sensitivity of the mouse
- */
- dxmouse(f, n)
- int f, n;
- {
- if (f && (n > 0) && (n < 256))
- {
- mcur_dx = ((char) n);
- Ikbdws(2, m_move);
- mlwrite("Horizontal mouse motion scale set to %d.", n);
- return(TRUE);
- }
- return(FALSE);
- }
-
- dymouse(f, n)
- int f, n;
- {
- if (f && (n > 0) && (n < 256))
- {
- mcur_dy = ((char) n);
- Ikbdws(2, m_move);
- mlwrite("Vertical mouse motion scale set to %d.", n);
- return(TRUE);
- }
- return(FALSE);
- }
- #endif /* AtST */
-
- #if VMS
- #include <stsdef.h>
- #include <ssdef.h>
- #include <descrip.h>
- #include <iodef.h>
- #include <ttdef.h>
-
- #define NIBUF 128 /* Input buffer size */
- #define NOBUF 1024 /* MM says bug buffers win! */
- #define EFN 0 /* Event flag */
-
- char obuf[NOBUF]; /* Output buffer */
- nt nobuf; /* # of bytes in above */
- char ibuf[NIBUF]; /* Input buffer */
- nt nibuf; /* # of bytes in above */
- int ibufi; /* Read index */
- int oldmode[2]; /* Old TTY mode bits */
- int newmode[2]; /* New TTY mode bits */
- short iochan; /* TTY I/O channel */
- #endif /* VMS */
-
- #if CPM
- #include <bdos.h>
- #endif /* CPM */
-
- #if MSDOS /* dal: Microsoft C v4.0 */
- #include <conio.h>
- #include <dos.h>
- #if TTFUNC
- #define SCRCHRS 1920 /* # of character on the screen */
- int *scrptr; /* screen base address */
- int abscup = 0; /* absolute cursor position */
- int curattr = 0x0700; /* current output attributes */
- #endif /* TTFUNC */
- #endif /* MSDOS */
-
- #if V7
- #include <sgtty.h> /* for stty/gtty functions */
- struct sgttyb ostate; /* saved tty state */
- struct sgttyb nstate; /* values for editor mode */
- #endif /* V7 */
-
- /*
- * This function is called once
- * to set up the terminal device streams.
- * On VMS, it translates SYS$INPUT until it
- * finds the terminal, then assigns a channel to it
- * and sets it raw. On CPM it is a no-op.
- * dal: added functions to determine screen size
- * at run time.
- */
- ttopen()
- {
- #if VMS
- struct dsc$descriptor idsc;
- struct dsc$descriptor odsc;
- char oname[40];
- int iosb[2];
- int status;
-
- odsc.dsc$a_pointer = "SYS$INPUT";
- odsc.dsc$w_length = strlen(odsc.dsc$a_pointer);
- odsc.dsc$b_dtype = DSC$K_DTYPE_T;
- odsc.dsc$b_class = DSC$K_CLASS_S;
- idsc.dsc$b_dtype = DSC$K_DTYPE_T;
- idsc.dsc$b_class = DSC$K_CLASS_S;
- do
- {
- idsc.dsc$a_pointer = odsc.dsc$a_pointer;
- idsc.dsc$w_length = odsc.dsc$w_length;
- odsc.dsc$a_pointer = &oname[0];
- odsc.dsc$w_length = sizeof(oname);
- status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
- if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
- exit(status);
- if (oname[0] == 0x1B)
- {
- odsc.dsc$a_pointer += 4;
- odsc.dsc$w_length -= 4;
- }
- }
- while (status == SS$_NORMAL);
- status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
- if (status != SS$_NORMAL)
- exit(status);
- status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
- oldmode, sizeof(oldmode), 0, 0, 0, 0);
- if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
- exit(status);
- newmode[0] = oldmode[0];
- newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
- status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
- newmode, sizeof(newmode), 0, 0, 0, 0);
- if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
- exit(status);
- #endif
- #if CPM
- #endif
- #if MSDOS
- union REGS rg;
- int mode;
-
- /* set cursor size */
- rg.h.ah = 1;
- rg.h.ch = 0;
- rg.h.cl = 12;
- int86( 16, &rg, &rg );
- #if TTFUNC
- /* get cursor location */
- rg.h.ah = 3;
- rg.h.bh = 0;
- int86( 16, &rg, &rg );
- abscup = rg.h.dh * 80; /* row */
- abscup += rg.h.dl; /* col */
- curattr = 0x0700; /* normal character attributes */
- rg.h.ah = 15;
- int86( 16, &rg, &rg ); /* get current display mode */
- mode = rg.h.al;
- scrptr = ((int *) ((mode == 7) ? 0xB0000000L : 0xB8000000L));
- #endif /* TTFUNC */
- #endif /* MSDOS */
- #if AtST
- register long *a;
- register int n;
-
- a = Physbase(); /* dal: clean up what GEM */
- a += 7680; /* leaves at end of screen */
- for( n=320; n--; *a++ = 0L ) /* (zero last 16 scanlines) */
- ;
- term.t_nrow = get_nrow() - 1; /* dal: get screen size */
- term.t_ncol = get_ncol(); /* from A-line variables */
- Cursconf(2,0); /* dal: blinking cursor */
- mouse_live(); /* dal: cursor stream mode */
- #endif
- #if V7
- gtty(1, &ostate); /* save old state */
- gtty(1, &nstate); /* get base of new state */
- nstate.sg_flags |= RAW;
- nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */
- stty(1, &nstate); /* set mode */
- #endif
- }
-
- /*
- * This function gets called just
- * before we go back home to the command interpreter.
- * On VMS it puts the terminal back in a reasonable state.
- * Another no-operation on CPM.
- */
- ttclose()
- {
- #if VMS
- int status;
- int iosb[1];
-
- ttflush();
- status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
- oldmode, sizeof(oldmode), 0, 0, 0, 0);
- if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
- exit(status);
- status = SYS$DASSGN(iochan);
- if (status != SS$_NORMAL)
- exit(status);
- #endif
- #if CPM
- #endif
- #if AtST
- Cursconf(2,0); /* dal: blinking cursor */
- mouse_dead(); /* dal: reset mouse mode */
- #endif
- #if MSDOS
- union REGS rg;
-
- /* reset cursor size */
- rg.h.ah = 1;
- rg.h.ch = 6;
- rg.h.cl = 7;
- int86(16, &rg, &rg);
- #endif
- #if V7
- stty(1, &ostate);
- #endif
- }
-
- /*
- * Write a character to the display.
- * On VMS, terminal output is buffered, and
- * we just put the characters in the big array,
- * after cheching for overflow. On CPM terminal I/O
- * unbuffered, so we just write the byte out.
- * Ditto on MS-DOS (use the very very raw console
- * output routine).
- */
- ttputc(c)
- {
- #if VMS
- if (nobuf >= NOBUF)
- ttflush();
- obuf[nobuf++] = c;
- #endif
- #if CPM
- bios(BCONOUT, c, 0);
- #endif
- #if AtST
- Bconout(2, c);
- #endif
- #if MSDOS
- c &= 0xFF;
- bdos(2, c, 0); /* conout() */
- #endif
- #if V7
- fputc(c, stdout);
- #endif
- }
-
- /*
- * Write a character to the display without VT52
- * emulation (if possible). On some systems, this
- * provides a faster output if VT52 functionality
- * is not needed. On VMS, terminal output is
- * buffered, and we just put the characters in
- * the big array, after cheching for overflow.
- * On CPM terminal I/O unbuffered, so we just
- * write the byte out. Ditto on MS-DOS (use the
- * very very raw console output routine).
- */
- ttqputc(c) /* dal: added */
- #if AtST
- register int c;
- #endif
- {
- #if VMS
- if (nobuf >= NOBUF)
- ttflush();
- obuf[nobuf++] = c;
- #endif
- #if CPM
- bios(BCONOUT, c, 0);
- #endif
- #if AtST
- /* dal: EXTERMEMLY non-portable, but FAST! c==r7 in Alcyon v4.14 */
- if(c < ' ')
- {
- asm(" move.w r7,-(sp) ");
- asm(" move.w #2,-(sp) "); /* Bconout(2, c); */
- }
- else
- {
- asm(" move.w r7,-(sp) "); /* Bconout(5, c); */
- asm(" move.w #5,-(sp) ");
- }
- asm(" move.w #3,-(sp) ");
- asm(" trap #13 ");
- asm(" addq.l #6,sp ");
- #endif
- #if MSDOS
- #if TTFUNC /* dal: this SHOULD be faster */
- c &= 0xFF; /* mask character */
- if (c < ' ') /* control character */
- {
- if (c == '\b')
- --abscup;
- else if (c == '\r')
- abscup -= (abscup % 80);
- return;
- }
- *(scrptr + abscup) = (curattr | c); /* put character w/ attr. */
- ++abscup; /* increment cursor position */
- #else
- union REGS rg;
-
- c &= 0xFF;
- rg.h.ah = 0x0E; /* write char as TTY */
- rg.h.al = c;
- int86(0x10, &rg, &rg); /* bios video service */
- /* ...and if all else fails... bdos(2, c, 0); */
- #endif
- #endif /* MSDOS */
- #if V7
- fputc(c, stdout);
- #endif
- }
-
- /*
- * Flush terminal buffer. Does real work
- * where the terminal output is buffered up. A
- * no-operation on systems where byte at a time
- * terminal I/O is done.
- */
- ttflush()
- {
- #if VMS
- int status;
- int iosb[2];
-
- status = SS$_NORMAL;
- if (nobuf != 0)
- {
- status = SYS$QIOW(EFN, iochan, IO$_WRITELBLK|IO$M_NOFORMAT,
- iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0);
- if (status == SS$_NORMAL)
- status = iosb[0] & 0xFFFF;
- nobuf = 0;
- }
- return (status);
- #endif
- #if CPM
- #endif
- #if MSDOS
- #if TTFUNC
- cursync(); /* move DOS cursor to internal cursor pos. */
- #endif
- #endif
- #if AtST
- #endif
- #if V7
- fflush(stdout);
- #endif
- }
-
- #if AtST
- #define LMOUSE (FUNC|ALT|0x74)
- #define RMOUSE (FUNC|ALT|0x75)
- /*
- * dal: Special subordinate input function to ease mouse button aliasing
- */
- _ttgetc()
- {
- register long key;
- register int kbs;
- register int c;
- register int k;
-
- key = Bconin(2); /* key code in upper word */
- kbs = Kbshift(-1); /* read shift and alt keys */
- c = (int)(key & 0xFF);
- k = (int)((key >> 16) & 0xFF);
- if (c==0 && k==0x03)
- return( CTLX|' ' );
- if ( c==0
- || k==0x0E || k==0x53 /* bs & del */
- || k==0x4B || k==0x4D /* arrow keys */
- || k==0x48 || k==0x50
- || k==0x52 || k==0x47 ) /* ins & clr */
- {
- if (k>=0x54 && k<=0x5D) /* shifted F1..f10 -> */
- k -= 0x19; /* unshifted codes */
- else if (k==0x48 || k==0x50) /* dal: kludge up/dn arrows */
- {
- if (kbs & 0x0C) /* dal: for ctrl & alt */
- k |= ALT;
- }
- else if ((k==0x74 || k==0x75) && !(kbs&0x04)) /* mouse? */
- k |= ALT;
- c = FUNC | k;
- if (kbs & 0x0F) /* Ctrl, Shift or Alt? */
- c |= SHFT;
- }
- return (c);
- }
- #endif
-
- /*
- * Read a character from the terminal,
- * performing no editing and doing no echo at all.
- * More complex in VMS than almost anyplace else, which
- * figures. Very simple on CPM, because the system can
- * do exactly what you want.
- */
- ttgetc()
- {
- #if VMS
- int status;
- int iosb[2];
- int term[2];
-
- while (ibufi >= nibuf)
- {
- ibufi = 0;
- term[0] = 0;
- term[1] = 0;
- status = SYS$QIOW(EFN, iochan, IO$_READLBLK|IO$M_TIMED,
- iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0);
- if (status != SS$_NORMAL)
- exit(status);
- status = iosb[0] & 0xFFFF;
- if (status!=SS$_NORMAL && status!=SS$_TIMEOUT)
- exit(status);
- nibuf = (iosb[0]>>16) + (iosb[1]>>16);
- if (nibuf == 0)
- {
- status = sys$qiow(EFN, iochan, IO$_READLBLK,
- iosb, 0, 0, ibuf, 1, 0, term, 0, 0);
- if (status != SS$_NORMAL
- || (status = (iosb[0]&0xFFFF)) != SS$_NORMAL)
- exit(status);
- nibuf = (iosb[0]>>16) + (iosb[1]>>16);
- }
- }
- return (ibuf[ibufi++] & 0xFF); /* Allow multinational */
- #endif
- #if CPM
- return (biosb(BCONIN, 0, 0));
- #endif
- #if AtST
- register int c;
-
- c = _ttgetc();
- if(mousef)
- {
- if(c == LMOUSE) /* execute left alias */
- {
- if (!mb_left)
- mlpending("Left mouse button not bound");
- return(mb_left);
- }
- if(c == RMOUSE) /* execute right alias */
- {
- if (!mb_right)
- mlpending("Right mouse button not bound");
- return(mb_right);
- }
- if(c == (SHFT|LMOUSE)) /* define left alias */
- {
- mlwrite("Bind what key to left mouse button?");
- Ikbdws(0, "\010"); /* no mouse motion */
- c = _ttgetc();
- if (c==0x07 || c==(FUNC|0x61))
- {
- mlpending("[aborted]");
- }
- else if (c==LMOUSE || c==(SHFT|LMOUSE))
- {
- mb_left = 0;
- mlpending("Left mouse button undefined.");
- }
- else
- mb_left = c;
- Ikbdws(2, m_move); /* mouse motion */
- return(0);
- }
- if (c == (SHFT|RMOUSE)) /* define left alias */
- {
- mlwrite("Bind what key to right mouse button?");
- Ikbdws(0, "\010"); /* no mouse motion */
- c = _ttgetc();
- if(c==0x07 || c==(FUNC|0x61))
- {
- mlpending("[aborted]");
- }
- else if(c==RMOUSE || c==(SHFT|RMOUSE))
- {
- mb_right = 0;
- mlpending("Right mouse button undefined.");
- }
- else
- mb_right = c;
- Ikbdws(2, m_move); /* mouse motion */
- return(0);
- }
- }
- return(c);
- #endif
- #if MSDOS
- register int c, k, m, kbs;
- union REGS rg;
-
- m = 0;
-
- rg.h.ah = 0x00; /* read kbd char and scan-code */
- int86( 0x16, &rg, &rg ); /* bios keyboard service */
- c = rg.h.al; /* ascii char */
- k = rg.h.ah; /* scancode */
-
- rg.h.ah = 0x02; /* read kbd shift status */
- int86( 0x16, &rg, &rg ); /* bios keyboard service */
- kbs = rg.h.al; /* kbd status */
-
- if ( k==0x0E || k==0x53 /* bs & del */
- || k==0x4B || k==0x4D /* arrow keys */
- || k==0x48 || k==0x50
- || k==0x52 || k==0x47 /* ins & clr */
- || (c==0 && k!=0x03) ) /* other function keys or
- {
- Alt-, but leave ^@ */
- if (k>=0x54 && k<=0x5D) /* shifted F1..f10 -> */
- k -= 0x19; /* unshifted codes */
-
- if (k==0x48 || k==0x50) /* dal: kludge up/dn arrows */
- if (kbs & 0x0C) /* dal: for ctrl & alt */
- k |= ALT;
-
- c = FUNC | k;
- if (kbs & 0x0F) /* Ctrl, Shift or Alt? */
- c |= SHFT;
- }
- return (c);
- #endif
- #if V7
- return(fgetc(stdin));
- #endif
- }
-
-
- /*
- * file vt52.c:
- *
- * The routines in this file
- * provide support for VT52 style terminals
- * over a serial line. The serial I/O services are
- * provided by routines in "termio.c". It compiles
- * into nothing if not a VT52 style device. The
- * bell on the VT52 is terrible, so the "beep"
- * routine is conditionalized on defining BEL.
- */
-
- #if VT52
-
- #if AtST
- get_nrow() /* dal: added */
- {
- asm( " dc.w $a000 " );
- asm( " move.w -$2a(a0),d0 " );
- asm( " addq.l #1,d0 " );
- }
-
- get_ncol() /* dal: added */
- {
- asm( " dc.w $a000 " );
- asm( " move.w -$2c(a0),d0 " );
- asm( " addq.l #1,d0 " );
- }
-
- #define NROW 25
- #else
- #define NROW 24 /* Screen size. */
- #endif
- #define NCOL 80 /* Edit if you want to. */
-
- #define BIAS 0x20 /* Origin 0 coordinate bias. */
- #define ESC 0x1B /* ESC character. */
- #define BEL 0x07 /* ascii bell character */
-
- extern int ttopen(); /* Forward references. */
- extern int ttgetc();
- extern int ttputc();
- extern int ttqputc(); /* dal: fast, non-VT52 output */
- extern int ttflush();
- extern int ttclose();
- extern int vt52move();
- extern int vt52eel();
- extern int vt52eep();
- extern int vt52beep();
- extern int vt52open();
- extern int vt52hglt();
- extern int vt52nrml();
-
- /*
- * Dispatch table. All the
- * hard fields just point into the
- * terminal I/O code.
- */
- TERM term =
- {
- NROW-1,
- NCOL,
- vt52open,
- ttclose,
- ttgetc,
- ttqputc,
- ttflush,
- vt52move,
- vt52eel,
- vt52eep,
- vt52beep,
- vt52hglt, /* dal: added */
- vt52nrml /* dal: added */
- };
-
- vt52move(row, col)
- {
- ttputc(ESC);
- ttputc('Y');
- ttputc(row+BIAS);
- ttputc(col+BIAS);
- }
-
- vt52eel()
- {
- ttputc(ESC);
- ttputc('K');
- }
-
- vt52eep()
- {
- ttputc(ESC);
- ttputc('J');
- }
-
- vt52beep()
- {
- #ifdef BEL
- ttputc(BEL);
- ttflush();
- #endif
- }
-
- vt52hglt()
- {
- ttputc(ESC);
- ttputc('p');
- }
-
- vt52nrml()
- {
- ttputc(ESC);
- ttputc('q');
- }
-
-
- vt52open()
- {
- #if V7
- register char *cp;
- char *getenv();
-
- if ((cp = getenv("TERM")) == NULL)
- {
- puts("Shell variable TERM not defined!");
- exit(1);
- }
- if (strcmp(cp, "vt52") != 0 && strcmp(cp, "z19") != 0)
- {
- puts("Terminal type not 'vt52'or 'z19' !");
- exit(1);
- }
- #endif
- ttopen();
- }
-
- #endif VT52
-
- /*
- * file ansi.c:
- *
- * The routines in this file
- * provide support for ANSI style terminals
- * over a serial line. The serial I/O services are
- * provided by routines in "termio.c". It compiles
- * into nothing if not an ANSI device.
- */
-
- #if ANSI
-
- #define NROW 24 /* Screen size. */
- #define NCOL 80 /* Edit if you want to. */
- #define BEL 0x07 /* BEL character. */
- define ESC 0x1B /* ESC character. */
-
- extern int ttopen(); /* Forward references. */
- extern int ttgetc();
- extern int ttputc();
- extern int ttflush();
- extern int ttclose();
- extern int ansimove();
- extern int ansieeol();
- extern int ansieeop();
- extern int ansibeep();
- extern int ansiopen();
- extern int ansihglt(); /* dal: added */
- extern int ansinrml(); /* dal: added */
-
- /*
- * Standard terminal interface
- * dispatch table. Most of the fields
- * point into "termio" code.
- */
- TERM term =
- {
- NROW-1,
- NCOL,
- ansiopen,
- ttclose,
- ttgetc,
- ttputc,
- ttflush,
- ansimove,
- ansieeol,
- ansieeop,
- ansibeep,
- ansihglt, /* dal: added */
- ansinrml /* dal: added */
- };
-
- ansimove(row, col)
- {
- ttputc(ESC);
- ttputc('[');
- ansiparm(row+1);
- ttputc(';');
- ansiparm(col+1);
- ttputc('H');
- }
-
- ansieeol()
- {
- ttputc(ESC);
- ttputc('[');
- ttputc('K');
- }
-
- ansieeop()
- {
- ttputc(ESC);
- ttputc('[');
- ttputc('J');
- }
-
- ansibeep()
- {
- ttputc(BEL);
- ttflush();
- }
-
- ansihglt() /* dal: added */
- {
- ttputc(ESC);
- ttputc('[');
- ttputc('1');
- ttputc('m');
- }
-
- ansinrml() /* dal: added */
- {
- ttputc(ESC);
- ttputc('[');
- ttputc('0');
- ttputc('m');
- }
-
- ansiparm(n)
- register int n;
- {
- register int q;
-
- q = n/10;
- if (q != 0)
- ansiparm(q);
- ttputc((n%10) + '0');
- }
-
- ansiopen()
- {
- #if V7
- register char *cp;
- char *getenv();
-
- if ((cp = getenv("TERM")) == NULL)
- {
- puts("Shell variable TERM not defined!");
- exit(1);
- }
- if (strcmp(cp, "vt100") != 0)
- {
- puts("Terminal type not 'vt100'!");
- exit(1);
- }
- #endif
- ttopen();
- }
-
- #endif ANSI
-
- /*
- * file: tcap.c
- *
- * This file does the term stuff for systems
- * that have 'termcap' flexibility.
- */
-
- #if TERMCAP
-
- #define NROW 24
- #define NCOL 80
- #define BEL 0x07
- #define ESC 0x1B
-
- extern int ttopen();
- extern int ttgetc();
- extern int ttputc();
- extern int ttflush();
- extern int ttclose();
- extern int tcapmove();
- extern int tcapeeol();
- extern int tcapeeop();
- extern int tcapbeep();
- extern int tcapopen();
- extern int tcaphglt(); /* dal: added */
- extern int tcapnrml(); /* dal: added */
- extern int tput();
- extern char *tgoto();
-
- /* mb: following 3 entries added: */
-
- extern int tgetent();
- extern char *tgetstr();
- extern int tputs();
-
- #define TCAPSLEN 315
-
- char tcapbuf[TCAPSLEN];
- char PC,
- *CM,
- *CL,
- *CE,
- *UP,
- *CD;
-
-
- TERM term =
- {
- NROW-1,
- NCOL,
- tcapopen,
- ttclose,
- ttgetc,
- ttputc,
- ttflush,
- tcapmove,
- tcapeeol,
- tcapeeop,
- tcapbeep,
- tcaphglt, /* dal: added */
- tcapnrml /* dal: added */
- };
-
- tcapopen()
- {
- char *getenv();
- char *t, *p, *tgetstr();
- char tcbuf[1024];
- char *tv_stype;
- char err_str[72];
-
- if ((tv_stype = getenv("TERM")) == NULL)
- {
- puts("Environment variable TERM not defined!");
- exit(1);
- }
-
- if((tgetent(tcbuf, tv_stype)) != 1)
- {
- sprintf(err_str, "Unknown terminal type %s!", tv_stype);
- puts(err_str);
- exit(1);
- }
-
- p = tcapbuf;
- t = tgetstr("pc", &p);
- if(t)
- PC = *t;
-
- CD = tgetstr("cd", &p);
- CM = tgetstr("cm", &p);
- CE = tgetstr("ce", &p);
- UP = tgetstr("up", &p);
-
- if(CD == NULL || CM == NULL || CE == NULL || UP == NULL)
- {
- puts("Incomplete termcap entry\n");
- exit(1);
- }
-
- if (p >= &tcapbuf[TCAPSLEN])
- {
- puts("Terminal description too big!\n");
- exit(1);
- }
- ttopen();
- }
-
- tcapmove(row, col)
- register int row, col;
- {
- putpad(tgoto(CM, col, row));
- }
-
- tcapeeol()
- {
- putpad(CE);
- }
-
- tcapeeop()
- {
- putpad(CD);
- }
-
- tcapbeep()
- {
- ttputc(BEL);
- }
-
- tcaphglt() /* dal: added */
- {
- }
-
- tcapnrml() /* dal: added */
- {
- }
-
- putpad(str)
- char *str;
- {
- tputs(str, 1, ttputc);
- }
-
- putnpad(str, n)
- char *str;
- {
- tputs(str, n, ttputc);
- }
- #endif TERMCAP
-
- /*
- * file ttfunc.c:
- *
- * dal: The routines in this file
- * provide support implementation of terminal control
- * through direct functions. The serial I/O services are
- * provided by routines in "termio.c". It compiles
- * into nothing if not an TTFUNC device.
- */
-
- #if TTFUNC
-
- #define NROW 25 /* Screen size. */
- #define NCOL 80 /* Edit if you want to. */
- #define BEL 0x07 /* BEL character. */
- #define ESC 0x1B /* ESC character. */
-
- extern int ttopen(); /* Forward references. */
- extern int ttgetc();
- extern int ttputc();
- extern int ttqputc();
- extern int ttflush();
- extern int ttclose();
- extern int funcmove();
- extern int funceeol();
- extern int funceeop();
- extern int funcbeep(); /* needs processing of ^G by ttputc */
- extern int funchglt(); /* dal: added */
- extern int funcnrml(); /* dal: added */
-
- /*
- * Standard terminal interface
- * dispatch table. Most of the fields
- * point into "termio" code.
- */
- TERM term =
- {
- NROW-1,
- NCOL,
- ttopen,
- ttclose,
- ttgetc,
- ttqputc,
- ttflush,
- funcmove,
- funceeol,
- funceeop,
- funcbeep,
- funchglt, /* dal: added */
- funcnrml /* dal: added */
- };
-
- funcmove(row, col)
- {
- union REGS rg;
-
- /* set cursor location */
- rg.h.ah = 2;
- rg.h.bh = 0;
- rg.h.dh = row;
- rg.h.dl = col;
- int86(16, &rg, &rg); /* set DOS physical cursor */
- abscup = (80 * row) + col; /* calculate internal cursor */
- }
-
- funceeol()
- {
- register int i, *ip;
-
- ip = scrptr + abscup;
- i = (abscup % 80);
- while(i++ < 80)
- *ip++ = 0x0700;
- }
-
- funceeop()
- {
- register int i, *ip;
-
- ip = scrptr + abscup;
- for(i=abscup; i<SCRCHRS; ++i)
- *ip++ = 0x0700;
- }
-
- funcbeep()
- {
- ttputc(BEL);
- ttflush();
- }
-
- funchglt() /* dal: added */
- {
- curattr = 0x0F00; /* highlight character attributes */
- }
-
- funcnrml() /* dal: added */
- {
- curattr = 0x0700; /* normal character attributes */
- }
-
- cursync() /* dal: make DOS cursor match internal position */
- {
- union REGS rg;
- int row, col;
-
- row = abscup / 80;
- col = abscup % 80;
- /* set cursor location */
- rg.h.ah = 2;
- rg.h.bh = 0;
- rg.h.dh = row;
- rg.h.dl = col;
- int86(16, &rg, &rg); /* set DOS physical cursor */
- }
- #endif
-